package main

import (
	"fmt"
	"time"
	"sync/atomic"
)

func main() {

	//messages := make(chan string)
	//signals := make(chan bool)
	//
	//select {
	//case msg := <-messages:
	//	fmt.Println("received message", msg)
	//default:
	//	fmt.Println("no message received")
	//}
	//
	//msg := "hi"
	//select {
	//case messages <- msg:
	//	fmt.Println("sent message", msg)
	//default:
	//	fmt.Println("no message sent")
	//}
	//
	//select {
	//case msg := <-messages:
	//	fmt.Println("received message", msg)
	//case sig := <-signals:
	//	fmt.Println("received signal", sig)
	//default:
	//	fmt.Println("no activity")
	//}

	//jobs := make(chan int, 5)
	//done := make(chan bool)
	//
	//go func() {
	//	for {
	//		j, more := <-jobs
	//		if more {
	//			fmt.Println("received job", j)
	//		} else {
	//			fmt.Println("received all jobs")
	//			done <- true
	//			return
	//		}
	//	}
	//}()
	//
	//for j := 1; j <= 3; j++ {
	//	jobs <- j
	//	fmt.Println("sent job", j)
	//}
	//close(jobs)
	//fmt.Println("sent all jobs")
	//
	//<-done
	//fmt.Println("DONE")

	//timer1 := time.NewTimer(2 * time.Second)
	//
	//<-timer1.C
	//fmt.Println("Timer 1 expired")
	//
	//timer2 := time.NewTimer(time.Second)
	//go func() {
	//	<-timer2.C
	//	fmt.Println("Timer 2 expired")
	//}()
	//
	//stop2 := timer2.Stop()
	//if stop2 {
	//	fmt.Println("Timer 2 stopped")
	//}

	//ticker := time.NewTicker(500 * time.Millisecond)
	//go func() {
	//	for t := range ticker.C {
	//		fmt.Println("Tick at", t)
	//	}
	//}()
	//
	//time.Sleep(1600 * time.Millisecond)
	//ticker.Stop()
	//fmt.Println("Ticker stopped")

	var ops uint64

	for i := 0; i < 50; i++ {
		go func() {
			for {
				atomic.AddUint64(&ops, 1)
				time.Sleep(time.Millisecond)
			}
		}()
	}

	time.Sleep(time.Second)

	opsFinal := atomic.LoadUint64(&ops)
	fmt.Println("ops:", opsFinal)

}
